<template>
  <view v-if="orderInfo">
    <u-navbar
      backIconColor="#fff"
      :is-back="true"
      title-color="#fff"
      title="提交订单"
      :background="scrollTop >= 100 ? background1 : background"
      :border-bottom="false"
    >
    </u-navbar>
    <view class="" style="position: relative">
      <view
        class="contentBg"
        :style="{
          paddingTop: `${statusBarHeight + navbarHeight}px`,
          backgroundImage: `url(${getImageUrl('bg.png')})`,
          height: `${200 + statusBarHeight}px`,
          top: `-${statusBarHeight + navbarHeight}px`
        }"
      >
      </view>
    </view>
    <!-- <u-navbar height="50" title="确定订单" title-size="36" title-color="#333"></u-navbar> -->
    <view style="position: relative; top: 20rpx; padding-bottom: 96rpx">
      <view class="locationView dervier-type">
        <view class="type-tabs dis-flex flex-y-between">
          <view
            v-if="
              orderInfo.supportDeliveryTypes &&
              orderInfo.supportDeliveryTypes.find((item) => item == 1)
            "
            @click="checkType(1)"
            :class="form.deliveryType == 1 ? '' : 'unchecked'"
            class="type"
          >
            快递发货
          </view>
          <view
            v-if="
              orderInfo.supportDeliveryTypes &&
              orderInfo.supportDeliveryTypes.find((item) => item == 3)
            "
            @click="checkType(3)"
            :class="form.deliveryType == 3 ? '' : 'unchecked'"
            class="type"
            >商家配送
          </view>
          <view
            v-if="
              orderInfo.supportDeliveryTypes &&
              orderInfo.supportDeliveryTypes.find((item) => item == 4)
            "
            @click="checkType(4)"
            :class="form.deliveryType == 4 ? '' : 'unchecked'"
            class="type"
            >线下核销
          </view>
          <view
            v-if="
              orderInfo.supportDeliveryTypes &&
              orderInfo.supportDeliveryTypes.find((item) => item == 2)
            "
            @click="checkType(2)"
            :class="form.deliveryType == 2 ? '' : 'unchecked'"
            class="type"
            >到店自提
          </view>
        </view>
        <view v-if="form.deliveryType == 1 || form.deliveryType == 3" class="">
          <view
            v-if="orderInfo.address"
            class="addressView"
            style="flex-flow: column; margin-top: 20rpx; align-items: flex-start"
            @click="onPickupAddress"
          >
            <view
              class="shopView-location dis-flex flex-y-between"
              style="margin-bottom: 20rpx; width: 100%"
            >
              <view
                >{{ orderInfo.address.areaName }} &nbsp;{{ orderInfo.address.detailAddress }}</view
              >
              <u-icon size="28" name="/static/more.png"></u-icon>
            </view>
            <view class="dis-flex">
              <u-icon size="28" name="/static/dw-g.png"></u-icon>
              <view class="addName" style="font-size: 28rpx">
                {{ orderInfo.address.name + ' ' + orderInfo.address.mobile }}
              </view>
            </view>
          </view>
          <view v-else class="addressView" @click="onPickupAddress">
            <u-icon size="28" name="/static/dw-g.png" style="margin-top: 4rpx"></u-icon>
            <view class="location">
              <view class="address">点击选择收货人</view>
            </view>
            <u-icon size="28" name="/static/more.png"></u-icon>
          </view>
        </view>
        <view v-if="form.deliveryType == 2 || form.deliveryType == 4">
          <view class="shopView">
            <view class="shopView-location">
              <text>商家地址：</text>
              <text>{{ orderInfo.shop.fullAddress }}</text>
            </view>
            <view class="phone">
              <text>联系方式：</text>
              <text>{{ orderInfo.shop.contactMobile }}</text>
            </view>
          </view>
        </view>
      </view>

      <view class="infoView">
        <view class="goodsView" v-for="(item, index) in orderInfo.items" :key="index">
          <u-image width="180" height="180" :src="item.picUrl" border-radius="10"></u-image>
          <view class="goodsData">
            <text class="goodsTitle oneline-hide-1">{{ item.spuName }}</text>
            <view class="skuView">
              <text v-if="item.properties" class="goodsSku">{{ formatProp(item.properties) }}</text>
              <text class="goodsNum">x1</text>
            </view>
            <view class="price">
              <text class="">原价:</text>
              <text>¥{{ formatPrice(orderInfo.price.totalPrice) }}</text>
              <text class="point" v-if="item.pointDeductCount"
                >{{ item.pointDeductCount }}积分抵¥{{ item.pointDeductPriceYuan }}</text
              >
            </view>
            <view class="point" style="margin-left: 0" v-if="item.cryptocurrencyDeductCount">
              {{ item.cryptocurrencyDeductCount }}联盟豆抵¥{{ item.cryptocurrencyDeductPriceYuan }}
            </view>
            <view class="goodsPrice" v-if="item.vipPrice">
              <text>会员价:</text>
              <text>¥{{ formatPrice(item.vipPrice) }}</text>
            </view>
          </view>
        </view>
      </view>
      <view class="infoView">
        <!-- 		<view class="totalView" style="padding-bottom: 10rpx;">
					<view class="totalTitle">原价</view>
					<view class="dis-flex flex-x-center">
						<view class="mr-20">¥{{ formatPrice(orderInfo.price.totalPrice )}}</view>
						<u-icon name="/static/selected.png" size="36rpx" v-if="PreType == 1"
							@click="onPreAll(0)"></u-icon>
						<u-icon v-else name="/static/unselect.png" size="36rpx" @click="onPreAll(1)"></u-icon>
					</view>
				</view> -->

        <view class="totalView" style="padding-bottom: 10rpx">
          <view class="totalTitle">套餐价</view>
          <view class="dis-flex flex-x-center">
            <view class="mr-20">¥{{ formatPrice(orderInfo.price.totalPrice) }}</view>
            <u-icon
              name="/static/selected.png"
              size="36rpx"
              v-if="PreType == 1"
              @click="onPreAll(0)"
            ></u-icon>
            <u-icon v-else name="/static/unselect.png" size="36rpx" @click="onPreAll(1)"></u-icon>
          </view>
        </view>

        <u-line v-if="!hasActive && orderInfo.firstOrderDiscount"></u-line>
        <view
          class="totalView"
          v-if="!hasActive && orderInfo.firstOrderDiscount"
          style="padding-bottom: 20rpx"
        >
          <view class="totalTitle">首单优惠</view>
          <view class="dis-flex flex-x-center">
            <view class="mr-20">
              ¥{{
                formatPrice((orderInfo.firstOrderDiscount * orderInfo.price.totalPrice) / 10)
              }}</view
            >
            <u-icon
              name="/static/selected.png"
              size="36rpx"
              v-if="PreType == 3"
              @click="onPreAll(3)"
            ></u-icon>
            <u-icon v-else name="/static/unselect.png" size="36rpx" @click="onPreAll(3)"></u-icon>
          </view>
        </view>
        <u-line
          v-if="!hasActive && orderInfo.price.totalVipPrice && !orderInfo.firstOrderDiscount"
        ></u-line>
        <view
          class="totalView"
          v-if="!hasActive && orderInfo.price.totalVipPrice && !orderInfo.firstOrderDiscount"
        >
          <view class="totalTitle dis-flex flex-y-center">
            <text>会员价</text>
            <text class="point">本单可享{{ (discount * 10).toFixed(0) }}折</text>
          </view>
          <view class="dis-flex flex-x-center">
            <view class="mr-20">¥{{ formatPrice(orderInfo.price.totalVipPrice) }}</view>
            <u-icon
              name="/static/selected.png"
              size="36rpx"
              v-if="PreType == 2"
              @click="onPreAll(0)"
            ></u-icon>
            <u-icon v-else name="/static/unselect.png" size="36rpx" @click="onPreAll(2)"></u-icon>
          </view>
        </view>
        <view class="open-vip" v-if="!hasActive && !isVip && orderInfo.price.totalVipPrice">
          <view class="vip-tl dis-flex flex-y-center">
            <view
              class="bt dis-flex flex-y-center flex-x-center"
              style="width: 100rpx; margin-right: 10rpx"
            >
              <u-icon class="bt-icon" name="/static/vip.png" size="36rpx"></u-icon>
              <text>VIP</text>
            </view>
            <view class="des">
              <text>开通会员，本单立享</text>
              <text class="col bold">{{ (discount * 10).toFixed(0) }}</text>
              <text class="col">折</text>
              <text>优惠</text>
            </view>
          </view>
          <view class="vip-qy" v-if="cards">
            会员费：充¥{{ (cards.deductPrice * 0.01).toFixed(0) }}送{{ cards.givePoint }}积分</view
          >
          <view class="description" v-if="cards">{{ cards.days }}天有效期 到期前可续费</view>
        </view>
        <u-line></u-line>
        <view class="totalView">
          <view class="totalTitle">配送费</view>
          <view>¥{{ formatPrice(orderInfo.price.deliveryPrice) }}</view>
        </view>
        <view class="totalView" v-if="!hasActive">
          <view class="totalTitle">优惠券</view>
          <view v-if="checkedCoupon" @click="showCouponModel = true" class="totalPrice"
            >{{ checkedCoupon.name }}
          </view>
          <view
            v-else-if="!checkedCoupon && orderInfo.coupons.length > 0"
            @click="showCouponModel = true"
            class="totalPrice"
            >选择优惠券
          </view>
          <view v-else class="totalPrice">无匹配优惠券</view>
        </view>

        <view class="totalView" v-if="orderInfo.price.couponPrice">
          <view class="totalTitle">优惠券抵扣</view>
          <view class="totalPrice" style="color: #ff2323"
            >-¥{{ formatPrice(orderInfo.price.couponPrice) }}
          </view>
        </view>
        <u-line></u-line>
        <view class="jisuan dis-flex">
          <text class="total-goods mr-20">共{{ countGoods }}样商品 </text>
          <text class="yh mr-20" v-if="subPrice">已优惠¥{{ (subPrice * 0.01).toFixed(2) }} </text>
          <text class="heji">合计：</text>
          <text class="total-Price">¥{{ formatPrice(orderInfo.price.payPrice) }}</text>
        </view>
        <u-gap height="100"></u-gap>
      </view>

      <view class="infoView">
        <view class="totalView">
          <view class="totalTitle">订单备注（选填）</view>
        </view>
        <view class="" style="">
          <textarea
            v-model="form.remark"
            style="flex-shrink: 0; margin: 10rpx 20rpx; font-size: 28rpx"
            ame=""
            placeholder="请输入备注信息"
            id=""
            cols="20"
            rows="5"
          ></textarea>
        </view>
      </view>
      <view class="footer-fill"></view>
    </view>
    <u-popup
      v-model="msgPopup"
      mode="center"
      width="550"
      height="480"
      :closeable="true"
      border-radius="15"
    >
      <view class="popup-box2" v-if="status">
        <u-icon style="margin-top: 30rpx" name="../../static/img/cg.png" size="80"></u-icon>
        <text>恭喜您支付成功</text>
        <p style="text-align: center">您已购买成功，我们将尽快为您服务！</p>
        <view class="popup-btn" style="background-color: #8cc340"> 知道了 </view>
      </view>
      <view class="popup-box2" v-else>
        <u-icon style="margin-top: 30rpx" name="../../static/img/shibai.png" size="80"></u-icon>
        <text style="color: #f54831">支付失败</text>
        <p style="text-align: center">哎呀，网络开小差了，请刷新重试！</p>
        <view class="popup-btn"> 重试一次 </view>
      </view>
    </u-popup>

    <view class="bottomView">
      <view class="bt-box dis-flex">
        <view style="flex: 1" v-if="PreType == 2 && isVip == false">
          <view class="totalPrice3"
            >待付款：<text>¥{{ (orderInfo.price.totalVipPrice * 0.01).toFixed(2) }}</text>
          </view>
        </view>
        <view style="flex: 1" v-else>
          <view class="totalPrice3"
            >待付款：<text>¥{{ (orderInfo.price.payPrice * 0.01).toFixed(2) }}</text></view
          >
        </view>
        <view>
          <view class="bottomBtn" @click.stop.prevent="onPayment()">下单支付</view>
        </view>
      </view>
    </view>

    <PayPopup ref="payPopupRef">
      <p style="font-size: 50rpx; font-weight: 600; padding: 20rpx; text-align: center">
        ¥{{ (settle.payPrice * 0.01).toFixed(2) }}
      </p>
    </PayPopup>
    <view class="tishi-warpper">
      <u-popup
        class="teshu"
        v-model="showSvipModel"
        backgroundColor="transparent"
        mode="center"
        width="610"
        height="auto"
        border-radius="20"
        :mask-close-able="false"
      >
        <view class="tishi-box">
          <view class="content">
            <view class="tl">温馨提示</view>
            <view class="vip-qy" v-if="cards">
              开通会员，充¥{{ (cards.deductPrice * 0.01).toFixed(0) }}送{{
                cards.givePoint
              }}积分</view
            >
            <view class="des">
              <text>本单立享</text>
              <text class="col bold">{{ (discount * 10).toFixed(0) }}</text>
              <text class="col">折</text>
              <text>优惠</text>
              <text style="color: red; margin-left: 10rpx"
                >¥{{
                  formatPrice(orderInfo.price.totalPrice - orderInfo.price.totalVipPrice)
                }}</text
              >
            </view>

            <view class="description" v-if="cards">{{ cards.days }}天有效期 到期前可续费</view>
            <view class="bt" @click="toSvip()">立即开通</view>
          </view>
          <view class="ts-close" @click="showSvipModel = false">
            <u-icon size="28" name="close" color="#ffffff"></u-icon>
          </view>
        </view>
      </u-popup>
    </view>

    <view class="tishi-warpper">
      <u-popup
        class="teshu"
        v-model="showFirstModel"
        backgroundColor="transparent"
        mode="center"
        width="610"
        height="auto"
        border-radius="20"
        :mask-close-able="false"
      >
        <view class="tishi-box">
          <view class="content">
            <view class="tl">温馨提示</view>
            <view class="vip-qy" v-if="cards">
              开通会员，充¥{{ (cards.deductPrice * 0.01).toFixed(0) }}送{{
                cards.givePoint
              }}积分</view
            >
            <view class="des">
              <text>本单立享</text>
              <text class="col bold">{{ discount }}</text>
              <text class="col">折</text>
              <text>优惠</text>
              <text style="color: red; margin-left: 10rpx"
                >¥{{
                  formatPrice(
                    orderInfo.price.totalPrice - (orderInfo.price.totalPrice * discount) / 10
                  )
                }}</text
              >
            </view>

            <view class="description" v-if="cards">{{ cards.days }}天有效期 到期前可续费</view>
            <view class="bt" @click="toSvip()">立即开通</view>
          </view>
          <view class="ts-close" @click="showFirstModel = false">
            <u-icon size="28" name="close" color="#ffffff"></u-icon>
          </view>
        </view>
      </u-popup>
    </view>

    <u-popup v-model="showCouponModel" mode="bottom" width="750" height="750" border-radius="20">
      <view class="popup-box">
        <view class="couponTl dis-flex flex-y-between flex-y-center">
          <view class="tl">优惠折扣券</view>
          <u-icon name="/static/close-t.png" size="36" @click="showCouponModel = false"></u-icon>
        </view>
        <scroll-view scroll-y="true" style="height: 650rpx">
          <view class="couponListView">
            <view
              class="couponView"
              :class="!item.match ? 'couponNotCan' : ''"
              v-for="(item, cIndex) in orderInfo.coupons"
              :key="item.id"
            >
              <view class="moneyView" v-if="item.discountType == 1">
                <view class="couponMoney"
                  >¥<text>{{ (item.discountPrice * 0.01).toFixed(0) }}</text>
                </view>
                <view class="couponTips">满减券</view>
              </view>
              <view class="moneyView" v-if="item.discountType == 2">
                <view class="couponMoney"
                  ><text>{{ item.discountPercent }}</text
                  >%</view
                >
                <view class="couponTips">折扣券</view>
              </view>
              <view class="lineView">
                <view class="circle"></view>
                <view class="line"></view>
                <view class="circle2"></view>
              </view>
              <view class="couponInfoView dis-flex flex-y-between flex-y-center">
                <view class="info dis-flex flex-y-between">
                  <view class="couponTitle">{{ item.name }}</view>
                  <view class="couponLabel">店铺券</view>
                  <view class="InfoView">
                    <view class="couponTime" v-if="item.validityType == 1">
                      有效日期{{ formatTime(item.validEndTime) }}</view
                    >
                    <view class="couponTime" v-else>自领取后{{ item.fixedEndTerm }}天有效</view>
                  </view>
                </view>
                <view
                  class="couponBtn"
                  v-if="item.id != checkedCoupon.id && item.match"
                  @click="onCouponGain(item, cIndex)"
                  >使用</view
                >
                <view class="couponBtn disabled" v-else-if="!item.match">不可使用</view>
                <view class="couponBtn disabled" v-else>已使用</view>
              </view>
            </view>
          </view>
        </scroll-view>
      </view>
    </u-popup>
    <!-- 	<u-popup v-model="showCoupon" height="700" mode="bottom">
			<view class="popup-box">
				<view class="couponListView">
					<view class="couponView" v-for="item in orderInfo.coupons" :key="item.id">
						<view class="moneyView" v-if="item.discountType == 1">
							<view class="couponMoney">¥<text>{{(item.discountPrice * 0.01).toFixed(2)}}</text></view>
							<view class="couponTips">满减券</view>
						</view>
						<view class="moneyView" v-if="item.discountType == 2">
							<view class="couponMoney">¥<text>{{(item.discountPercent * 0.1).toFixed(2)}}</text></view>
							<view class="couponTips">折扣券</view>
						</view>
						<view class="lineView">
							<view class="circle"></view>
							<view class="line"></view>
							<view class="circle2"></view>
						</view>
						<view class="couponInfoView">
							<view class="couponTitle">{{item.name}}</view>
							<view class="InfoView">
								<view class="couponTime" v-if="item.validityType == 1">
									有效日期{{ formatTime(item.validEndTime)}}</view>
								<view class="couponTime" v-else>自领取后{{item.fixedEndTerm}}天有效</view>
								<view class="couponBtn" @click="gainOrderInfo(item)">选择</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup> -->
  </view>
</template>

<script>
import PayPopup from '@/components/PayPopup.vue'
let systemInfo = uni.getSystemInfoSync()
export default {
  components: {
    PayPopup
  },
  data() {
    return {
      scrollTop: 0,
      background: {
        background: 'transparent'
      },
      background1: {
        background: '#10A28F'
      },
      statusBarHeight: systemInfo.statusBarHeight,
      status: 1,
      showCouponModel: false,
      showSvipModel: false,
      showFirstModel: false,
      resStatus: '',
      msgPopup: false,
      group_product_id: '',
      pickupPopup: false,
      goodsType: 1, //1-其他商品，2，预售商品
      orderType: 4, //1-当日达订单，2-次日达订单，3-抢购订单
      goodsInfo: [],
      goodsPrice: 0,
      totalPrice: 0,
      pointDeductCount: 0,
      discount: 0,
      pointDeductPriceYuan: 0,
      vipPrice: 0,
      user_coupon_id: '', //优惠劵id
      subPrice: '', //优惠价格
      pickupInfo: '',
      username: '',
      userphone: '',
      payMethod: '',
      detailAddress: '',
      settle: {},
      payOrderId: '',
      catIds: [],
      couponList: '',
      checkedCoupon: '',
      orderInfo: null,
      tips: '尊敬的用户，您还未开通平台会员， 您暂时不能享受会员价下单操作！',
      form: {
        items: [],
        couponId: '',
        deliveryType: null,
        addressId: '',
        pickUpStoreId: '',
        receiverName: '',
        receiverMobile: '',
        seckillActivityId: '',
        combinationActivityId: '',
        combinationHeadId: '',
        bargainRecordId: '',
        remark: '',
        channelCode: 'mock',
        useVipPrice: false,
        usePointDeduction: false,
        grouponPackageId: '',
        useCryptocurrencyDeduction: false,
        useFirstOrderDiscount: false
      },
      res2: '',
      PrePoints: 0,
      PreType: 1, //支付价格 1 原价 2 会员价
      hasActive: false,
      isVip: false,
      cards: null,
      countGoods: 0,
      cryptocurrencyDeductCount: 0,
      cryptocurrencyDeductPriceYuan: 0
    }
  },
  onLoad(res) {
    this.initData(res)
  },
  onShow() {},
  onPageScroll: function (e) {
    //nvue暂不支持滚动监听，可用bindingx代替
    // console.log("滚动距离为：" + e.scrollTop);
    this.scrollTop = e.scrollTop // 更新滚动位置
  },
  computed: {
    formatPrice() {
      return (e) => {
        // if (e.toString().includes(".")) {
        // 	return e
        // }
        return (Number(e) * 0.01).toFixed(2)
      }
    },
    formatProp() {
      return (e) => {
        let arr = ''
        if (e) {
          e.forEach((item) => {
            arr += item.valueName
          })
        }
        return arr
      }
    },
    // 转换字符数值为真正的数值
    navbarHeight() {
      // #ifdef APP-PLUS || H5
      return this.height ? this.height : 50
      // #endif
      // #ifdef MP
      // 小程序特别处理，让导航栏高度 = 胶囊高度 + 两倍胶囊顶部与状态栏底部的距离之差(相当于同时获得了导航栏底部与胶囊底部的距离)
      // 此方法有缺陷，暂不用(会导致少了几个px)，采用直接固定值的方式
      // return menuButtonInfo.height + (menuButtonInfo.top - this.statusBarHeight) * 2;//导航高度
      let height = systemInfo.platform == 'ios' ? 44 : 48
      return this.height ? this.height : height
      // #endif
    }
  },
  onShow() {
    this.$u
      .get('/app-api/member/vip/my', {
        profile: 1,
        cards: 1
      })
      .then((res) => {
        this.isVip = res.data.valid
        this.cards = res.data.cards.length > 0 ? res.data.cards[0] : null
      })
  },
  methods: {
    toSvip() {
      this.showSvipModel = false
      this.$u.route('/users/svip')
    },
    onPreAll(type) {
      if (type == 2) {
        this.discount = this.orderInfo.price.totalVipPrice / this.orderInfo.price.totalPrice
        if (this.isVip == false) {
          this.showSvipModel = true
          return
        }
        this.PreType = type
        this.PrePoints = 0
        this.subPrice = this.orderInfo.price.payPrice - this.vipPrice
        this.form.useVipPrice = true
        this.form.usePointDeduction = false
        this.form.useCryptocurrencyDeduction = false
      } else if (type == 3) {
        if (this.isVip == false) {
          this.discount = this.orderInfo.firstOrderDiscount
          this.showFirstModel = true
          return
        }
        this.PreType = type
        this.form.useFirstOrderDiscount = true
        this.form.useVipPrice = false
        this.form.usePointDeduction = false
        this.form.useCryptocurrencyDeduction = false
      } else {
        this.PreType = 1
        this.form.useVipPrice = false
        this.subPrice = 0
      }
      this.initData()
    },
    onPrePoints(type) {
      this.PrePoints = type
      this.form.useVipPrice = false
      if (type == 1) {
        if (this.orderInfo.totalPoint >= this.pointDeductCount) {
          this.PreType = 1
          this.form.usePointDeduction = true
          this.form.useCryptocurrencyDeduction = false
        } else {
          this.$u.toast('当前积分不足')
          this.PrePoints = 0
          return
        }
      } else if (type == 2) {
        if (
          this.orderInfo.price.totalCryptocurrencyDeductCount < this.orderInfo.totalCryptocurrency
        ) {
          this.PreType = 1
          this.form.useCryptocurrencyDeduction = true
          this.form.usePointDeduction = false
          this.form.useVipPrice = false
        } else {
          this.$u.toast('当前联盟豆不足')
          this.PrePoints = 0
          return
        }
      } else {
        this.form.useFirstOrderDiscount = false
        this.form.useVipPrice = false
        this.form.usePointDeduction = false
        this.form.useCryptocurrencyDeduction = false
        this.PreType = 1
      }

      this.initData()
    },
    checkType(type) {
      this.form.deliveryType = type
    },
    initData(res2) {
      this.goodsInfo = res2 && res2.items ? JSON.parse(res2.items) : ''
      if (this.goodsInfo) {
        this.form.items = this.goodsInfo.map((item) => {
          return {
            skuId: item.skuId,
            count: item.count,
            cartId: item.cartId
          }
        })
      }
      this.form.seckillActivityId = res2 && res2.seckillActivityId ? res2.seckillActivityId : ''
      this.form.grouponPackageId =
        res2 && res2.grouponPackageId ? res2.grouponPackageId : '1915971543742169089'
      this.form.combinationActivityId =
        res2 && res2.combinationActivityId ? res2.combinationActivityId : ''
      this.form.combinationHeadId = res2 && res2.combinationHeadId ? res2.combinationHeadId : ''
      if (this.form.seckillActivityId || this.form.combinationActivityId) {
        this.hasActive = true
      }

      this.$u
        .post('/app-api/trade/order/settlement', this.form)
        .then((res) => {
          if (res.code != 0) {
            this.$u.toast(res.msg)
            setTimeout(function () {
              uni.navigateBack()
            }, 1500)
          }

          this.settle = res.data.price
          this.orderInfo = res.data
          if (!this.orderInfo.firstOrderDiscount) {
            this.discount = this.orderInfo.price.totalVipPrice / this.orderInfo.price.totalPrice
          } else {
            this.discount = this.orderInfo.firstOrderDiscount / this.orderInfo.price.totalPrice
          }

          this.form.addressId = res.data.address?.id
          if (
            this.orderInfo.supportDeliveryTypes &&
            this.orderInfo.supportDeliveryTypes.length > 0
          ) {
            this.form.deliveryType = this.orderInfo.supportDeliveryTypes[0]
          }
          let _pointDeductCount = 0
          let _vipPrice = 0
          let _pointDeductPriceYuan = 0
          let _cryptocurrencyDeductCount = 0
          let _cryptocurrencyDeductPriceYuan = 0
          res.data.items.forEach((item) => {
            _pointDeductCount += item.pointDeductCount * item.count
            _cryptocurrencyDeductCount += item.cryptocurrencyDeductCount * item.count
            _cryptocurrencyDeductPriceYuan += item.cryptocurrencyDeductPriceYuan * item.count
            _pointDeductPriceYuan += item.pointDeductPriceYuan * 100 * item.count
            // _vipPrice += item.vipPrice * item.count
          })
          this.pointDeductCount = _pointDeductCount
          // this.vipPrice = _vipPrice
          this.pointDeductPriceYuan = _pointDeductPriceYuan
          this.cryptocurrencyDeductCount = _cryptocurrencyDeductCount
          this.cryptocurrencyDeductPriceYuan = _cryptocurrencyDeductPriceYuan
          this.countGoods = res.data.items.length

          // console.log(res.data.price.totalVipPrice,res.data.price.totalPrice)
          return Promise.resolve(res.data)
        })
        .then((res) => {})
    },
    gainOrderInfo(e) {
      this.checkedCoupon = e
      this.showCouponModel = false
      this.$u
        .post('/app-api/trade/order/settlement', {
          items: this.form.items,
          deliveryType: 1,
          couponId: e.id
        })
        .then((res) => {
          this.settle = res.data.price
          return Promise.resolve(res.data)
        })
    },
    onCouponGain(e) {
      this.checkedCoupon = e
      this.form.couponId = e.id
      this.showCouponModel = false
      this.initData()
    },
    onPickup() {
      this.pickupPopup = true
    },
    onConfirm() {
      // if (this.$u.test.isEmpty(this.pickup_phone)) {
      // 	this.$u.toast('请输入联系电话');
      // 	return
      // }
      this.username = this.pickup_name
      this.userphone = this.pickup_phone
      this.pickupPopup = false
    },
    onPickupAddress() {
      uni.$on('manage', (e) => {
        this.form.receiverName = e.name
        this.form.receiverMobile = e.mobile
        this.form.addressId = e.id
        this.initData(this.res2)
        uni.$off('manage')
      })
      this.$utils.route('/other/address-manage/address-manage?isCheck=' + true)
    },

    onPayment() {
      // if (!this.form.receiverName) {
      // 	this.$u.toast('请选择收货人信息');
      // 	return
      // }
      if (this.PreType == 2 && this.isVip == false) {
        this.showSvipModel = true
        return
      }
      if (this.payOrderId) {
        uni.dialog.confirm('温馨提示', '请勿重复下单，是否查看订单付情况？', () => {
          uni.navigateTo({
            url: '/goods/order-list/order-list'
          })
        })
        return
      }
      this.$u.api.setOrderCreate(this.form).then((res) => {
        if (res.code == 400) {
          this.$u.toast(res.msg)
          return
        }
        this.payOrderId = res.data.tradeNo
        this.$refs.payPopupRef.open(this.payOrderId, '', res.data.price === 0)
      })
    }
  }
}
</script>

<style>
@import url('order-confirm.css');

page {
  background: #f5f5f5;
}
</style>
<style lang="scss" scoped>
.open-vip {
  padding: 20rpx;

  .vip-tl {
    padding-bottom: 10rpx;

    .bt {
      width: 150rpx;
      height: 50rpx;
      background: linear-gradient(90deg, #f5cd71, #f5e39d);
      border-radius: 25rpx;
      font-size: 24rpx;
      color: #995406;
    }
  }
}

.vip-qy {
  font-weight: 600;
  font-size: 28rpx;
  color: #333333;
  margin: 10rpx 0;
}

.description {
  font-size: 24rpx;
  color: #999999;
}

.des {
  font-size: 28rpx;
  color: #333333;

  .col {
    color: #fa453c;
  }

  .bold {
    font-size: 36rpx;
    margin: 0 2rpx;
  }
}

.jisuan {
  justify-content: flex-end;
  padding: 30rpx 20rpx;
  align-items: flex-end;

  .total-goods {
    font-size: 28rpx;
    color: #333333;
  }

  .yh {
    font-size: 26rpx;
    color: #999999;
    padding-bottom: 2rpx;
  }

  .heji {
    font-size: 28rpx;
  }

  .total-Price {
    font-size: 32rpx;
    color: #fa453c;
  }
}

.popup-box {
  padding: 0;

  .couponTl {
    padding: 0 20rpx;
    height: 100rpx;
    background: #f5f5f5;
  }

  .couponListView {
    padding: 30rpx 20rpx;

    .couponView {
      display: flex;
      height: 161rpx;
      margin-bottom: 19rpx;

      .moneyView {
        background-color: #10a28f;
        width: 160rpx;
        color: #ffffff;
        display: flex;
        flex-flow: column;
        justify-content: center;
        align-items: center;

        .couponMoney {
          font-size: 36rpx;
          margin-bottom: 10rpx;

          text {
            font-size: 56rpx;
            font-weight: 600;
          }
        }

        .couponTips {
          font-size: 24rpx;
        }
      }

      .couponInfoView {
        flex: 1;
        background: #ffffff;
        border-radius: 8rpx;
        border: 1px solid #e6e6e6;
        margin-left: -15rpx;
        padding: 20rpx;

        .info {
          height: 100%;
          flex-flow: column;
          flex: 1;

          .couponTitle {
            font-size: 30rpx;
            color: #333333;
          }

          .couponLabel {
            font-size: 20rpx;
            color: #fa453c;
            border-radius: 20rpx;
            border: 1px solid #fa453c;
            padding: 2rpx 0;
            width: 109rpx;
            text-align: center;
            // height: 40rpx;
            // line-height: 40rpx;
          }

          .couponTime {
            font-size: 20rpx;
            color: #999999;
          }
        }

        .couponBtn {
          // width: 96rpx;
          height: 48rpx;
          background: #10a28f;
          border-radius: 23rpx;
          font-size: 26rpx;
          color: #ffffff;
          line-height: 48rpx;
          text-align: center;
          padding: 0 15rpx;
        }

        .disabled {
          background: #cccccc;
        }
      }

      .lineView {
        display: flex;
        flex-direction: column;
        align-items: center;
        overflow: hidden;
        margin-left: -15rpx;
        height: 161rpx;
        position: relative;

        .circle {
          width: 30rpx;
          height: 30rpx;
          border-radius: 50%;
          background: #fff;
          margin-top: -15rpx;
          border: 1px solid #e6e6e6;
        }

        .circle2 {
          width: 30rpx;
          height: 30rpx;
          border-radius: 50%;
          background: #fff;
          margin-bottom: -15rpx;
          border: 1px solid #e6e6e6;
        }

        .line {
          flex: 1;
          width: 1rpx;
          /* 设置元素的宽度 */
          background-color: #e6e6e6;
          /* 左边虚线 */
        }
      }
    }

    .couponNotCan {
      .moneyView {
        background-color: #cccccc;
      }
    }
  }
}

::v-deep.tishi-warpper .teshu .u-mode-center-box {
  background-color: transparent !important;
}

.tishi-box {
  position: relative;
  display: flex;
  flex-flow: column;

  .content {
    background-color: #fff;
    border-radius: 20rpx;
    padding: 30rpx 20rpx;
  }

  .ts-close {
    margin: auto;
    margin-top: 50rpx;
    width: 64rpx;
    height: 64rpx;
    border: 4rpx solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.content {
  text-align: center;

  .tl {
    padding: 20rpx 0 40rpx 0;
    margin: auto;
    font-weight: 600;
    font-size: 34rpx;
    color: #333333;
  }

  .des {
    font-size: 30rpx;
    line-height: 50rpx;
    padding: 0 40rpx;
  }

  .bt {
    width: 280rpx;
    height: 80rpx;
    background: #10a28f;
    border-radius: 40rpx;
    margin: auto;
    margin-top: 70rpx;
    margin-bottom: 10rpx;
    line-height: 80rpx;
    font-size: 34rpx;
    color: #ffffff;
  }
}
</style>
